package com.k.demo.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.k.demo.filter.CrosFilter;
import com.k.demo.listener.AppListener;

@Configuration
public class WebConfig {
	// 配置跨域过滤器
	@Bean
	public FilterRegistrationBean crossFilter() {
		FilterRegistrationBean bean = new FilterRegistrationBean(new CrosFilter());
		bean.addUrlPatterns("/*");
		return bean;
	}

	// 配置监听器
	@Bean
	public ServletListenerRegistrationBean servletListenerRegistrationBean() {
		ServletListenerRegistrationBean bean = new ServletListenerRegistrationBean();
		bean.setListener(new AppListener());
		return bean;
	}
}
